package com.zm.demo.core.concurrent;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import static java.lang.System.out;

/**
 * @author zoum
 * @create 2019/6/18 18:53
 */
public class ThreadPoolExecutorDemo {

    public static void main(String[]args) throws Exception{

        ThreadPoolExecutor pool = new ThreadPoolExecutor(1, 10, 0, TimeUnit.MINUTES, new ArrayBlockingQueue<Runnable>(3));
//        ExecutorService pool = Executors.newCachedThreadPool();
        for (int i = 0; i < 10; i++) {
            out.println("========" + i);
            pool.execute(() -> {
                try {
                    out.println(Thread.currentThread().getName() + "=== run");
                    Thread.sleep(100L);
                }catch (Exception e){

                }
            });
        }
        pool.shutdown();
        out.println("getActiveCount: " + pool.getActiveCount());
    }
}
